home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12392 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  50 lines

  1. Path: news.ichange.com!newsmaster
  2. From: Jesse Liberty <jl@staff.ichange.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help! Newbie question ...
  5. Date: Tue, 19 Mar 1996 11:58:37 -0500
  6. Organization: AT&T
  7. Message-ID: <314EE7BD.16BD@staff.ichange.com>
  8. References: <4ilkfu$41q@Kaos.deepcove.com> <314EB00C.34BD@bnr.ca>
  9. NNTP-Posting-Host: 140.244.99.60
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14. CC: jl@staff.ichange.com
  15.  
  16. Joseph Bell wrote:
  17. > Sean Affleck wrote:
  18. > >
  19. > > Is this legal ?
  20. > >
  21. > > class A {...};
  22. > >
  23. > > A f();
  24. > >
  25. > > main() {
  26. > >   A a = f();
  27. > > }
  28. > >
  29. > > A f()
  30. > > {
  31. > >    A fa;
  32. > >    return fa;
  33. > > }
  34. > >
  35. > Yes, this is perfectly legal, but with a caveat.  If you want to do this
  36. > you should define a _copy constructor_.  ...
  37.  
  38. Well, yes, if you were going to make a copy and pass it by value you'd want a copy constructor IF class A had any pointers 
  39. (of course, if it didn't have pointers, a shallow copy as made by the default copy constructor would no doubt be just fine). 
  40. The other issue, however, is that you almost certainly don't want to be passing this object around by value.
  41. ------
  42. Jesse Liberty [AT&T New Media Services]
  43. jl@staff.ichange.com    ZDNet: 72241,72
  44. Teach Yourself C++ In 21 Days. Sams 1994
  45. Teach Yourself MORE C++ In 21 Days. Sams 1996
  46. Teach Yourself ANSI C++ In 21 Days. Sams 1996
  47. C++: An Introduction To Programming. Que 1996
  48.